package logic

import (
	"2210a/user-profile/pkg"
	"2210a/user-profile/userprofileapi/internal/svc"
	"2210a/user-profile/userprofileapi/internal/types"
	"2210a/user-profile/userprofilerpc/userprofilerpc"
	"context"

	"github.com/zeromicro/go-zero/core/logx"
)

type PerfectLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewPerfectLogic(ctx context.Context, svcCtx *svc.ServiceContext) *PerfectLogic {
	return &PerfectLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *PerfectLogic) Perfect(req *types.PerfectHandlerRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line
	perfect, err := l.svcCtx.UserprofileRpc.Perfect(l.ctx, &userprofilerpc.PerfectRequest{
		Id:        req.Id,
		Avatar:    req.Avatar,
		Nickname:  req.Nickname,
		Mobile:    req.Mobile,
		Gender:    req.Gender,
		Birthday:  req.Birthday,
		Introduce: req.Introduce,
	})
	if err != nil {
		return nil, err
	}
	if err != nil {
		return &types.Response{
			Code:    500,
			Message: pkg.Tri(err.Error()),
			Data:    nil,
		}, nil
	}
	return &types.Response{
		Code:    200,
		Message: "个人信息修改成功",
		Data:    perfect.Id,
	}, nil
	return
}
